﻿/**
 * 
 * Copyright 2009, 2010 Mike Jamer [email: mikejamer@gmail.com ]
 * 
 * This File is part of Moose IRC
 * 
 * MooseIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MooseIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MooseIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace moose.irc
{
    /// <summary>
    /// Manages Channel Collection
    /// </summary>
    public class IrcChannelCollection : object
    {
        /// <summary>
        /// Collcetion of managed channels
        /// [name, Channel]
        /// </summary>
        private Dictionary<string, IrcChannel> m_dictChannels;

        /// <summary>
        /// Initialize Channel Collection
        /// </summary>
        public IrcChannelCollection()
            : base()
        {
            m_dictChannels = new Dictionary<string, IrcChannel>();
            return;
        }

        /// <summary>
        /// Gets IRC Channel, or creates one
        /// </summary>
        /// <param name="channel_name">Name of Channel</param>
        /// <returns>Channel Instance</returns>
        public IrcChannel get_channel(string channel_name)
        {
            if (m_dictChannels.ContainsKey(channel_name))
                return m_dictChannels[channel_name];

            m_dictChannels[channel_name] = new IrcChannel(channel_name);
            return m_dictChannels[channel_name];
        }

        /// <summary>
        /// Enumerates all managed channels
        /// </summary>
        /// <returns>All Channel References</returns>
        public IEnumerable<IrcChannel> get_all()
        {
            return m_dictChannels.Values;
        }

        /// <summary>
        /// Determines if a channel already exists
        /// </summary>
        /// <param name="channel_name">name of channel</param>
        /// <returns>true if channel has already been created</returns>
        public bool channel_exists(string channel_name)
        {
            return m_dictChannels.ContainsKey(channel_name);
        }

        /// <summary>
        /// Remove a channel
        /// </summary>
        /// <param name="channel_name">removes a channel</param>
        public void remove_channel(string channel_name)
        {
            m_dictChannels.Remove(channel_name);
            return;
        }

        /// <summary>
        /// remove all channels
        /// </summary>
        public void remove_all()
        {
            m_dictChannels.Clear();
            return;
        }

    }
}
